package com.qifenqian.turbot.module.adapter.itemdecoration

import android.content.Context
import android.graphics.Rect
import android.support.v7.widget.RecyclerView
import android.view.View
import org.jetbrains.anko.dip

/**
 * @author H
 * @createTime 2018/12/26 14:48
 * @description RecyclerView的横向的分隔(给每个item设置了同样的边框宽度,与LinearItemDecoration的首尾项不同)
 * @see
 * @since
 */
class GridItemDecoration(context: Context, spaceWidth: Int = 4) : RecyclerView.ItemDecoration() {

    private var mContext: Context? = null
    private var mSpaceWidth = 4

    init {
        mContext = context
        mSpaceWidth = mContext!!.dip(spaceWidth)
    }

    override fun getItemOffsets(outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State) {
        //item所在的行数
//        (parent.layoutManager as GridLayoutManager).spanSizeLookup.getSpanGroupIndex(parent.getChildAdapterPosition(view), spanCount)
        super.getItemOffsets(outRect, view, parent, state)
        val position = parent.getChildAdapterPosition(view)
        outRect.left = mSpaceWidth / 2
        outRect.top = mSpaceWidth / 2
        outRect.right = mSpaceWidth / 2
        outRect.bottom = mSpaceWidth / 2
    }
}
